﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace WorkStation.Frameworks.EasyBus.MessageQueue
{
    /// <summary>
    /// 消息通道接口
    /// </summary>
    public interface IChannel : IDisposable
    {
        /// <summary>
        /// 终结点
        /// </summary>
        IEndpoint Endpoint { get; set; }

        /// <summary>
        /// 向通道写入消息
        /// </summary>
        /// <param name="msg">消息</param>
        void WriteMsg(Message msg);

        /// <summary>
        /// 从通道中读取消息
        /// </summary>
        /// <returns>消息对象</returns>
        Message ReadMsg();
    }

    /// <summary>
    /// 消息通道基类
    /// </summary>
    public abstract class ChannelBase : IChannel
    {
        /// <summary>
        /// 终结点
        /// </summary>
        public IEndpoint Endpoint { get; set; }

        /// <summary>
        /// 向通道写入消息
        /// </summary>
        /// <param name="msg">消息</param>
        public abstract void WriteMsg(Message msg);

        /// <summary>
        /// 从通道中读取消息
        /// </summary>
        /// <returns>消息对象</returns>
        public abstract Message ReadMsg();

        /// <summary>
        /// 释放资源
        /// </summary>
        public abstract void Dispose();
    }
}
